import * as actionTypes from './constants';
import { 
  getTopBanners,
  getHotRecommends,
  getNewAlbums,
  // getTopLists
  getArtistList
 } from '../../../../../services/recommend'




const changeTopBannerAction = (res) => ({
  //定义的类型校验
  type: actionTypes.CHANGE_TOP_BANNERS,
  topBanners: res.banners
})

const changeHotRecommendAction =(res) => ({
  type: actionTypes.CHANGE_HOT_RECOMMEND,
  hotRecommends: res.result
})

const changeNewAlbumAction = (res) => ({
  type: actionTypes.CHANGE_NEW_ALBUM,
  newAlbums: res.albums
})

// const changeTopListAction = (res) => ({
//   type: actionTypes.CHANGE_UP_RANKING,
//   topLists: res.list
// })

const changeSettleSingsAction = (res) => ({
  type: actionTypes.CHANGE_SETTLE_SONGER,
  settleSings: res.artists
})


//从最外层Services  recommerd.js 里面getTopBanners拿到数据 封装到getTopBannerAction 以便派发
export const getTopBannerAction = () => {
  return dispatch => {
    getTopBanners().then( res => {
      dispatch(changeTopBannerAction(res))
    })
  }
}


export const getHotRecommendAction =(limit) => {
  return dispatch => {
    getHotRecommends(limit).then(res => {
      dispatch(changeHotRecommendAction(res))
    })
  }
}


export const getNewAlbumAction = (limit) => {
  return dispatch => {
    getNewAlbums(limit).then(res => {
      dispatch(changeNewAlbumAction(res))
      // console.log(res)
    })
  }
}


// export const getTopListAction = () => {
//   return dispatch => {
//     getTopLists().then(res => {
//       // dispatch(changeTopListAction(res))
//       console.log(res)
//     })
//   }
// }


export const getSettleSingers = () => {
  return dispath => {
    getArtistList(5, 5001).then(res => {
      dispath(changeSettleSingsAction(res))
    })
  }
}






// import * as actionTypes from './constants';

// import { getNewAlbums } from '@/services/recommend';

// import { 
//   getTopBanners,
//   getHotRecommends,
//   getTopList
// } from '@/services/recommend';

// const changeTopBannerAction = (res) => ({
//   type: actionTypes.CHANGE_TOP_BANNERS,
//   topBanners: res.banners
// });

// const changeHotRecommendAction = (res) => ({
//   type: actionTypes.CHANGE_HOT_RECOMMEND,
//   hotRecommends: res.result
// })

// const changeNewAlbumAction = (res) => ({
//   type: actionTypes.CHANGE_NEW_ALBUM,
//   newAlbums: res.albums
// })

// const changeUpRankingAction = (res) => ({
//   type: actionTypes.CHANGE_UP_RANKING,
//   upRanking: res.playlist
// })

// const changeNewRankingAction = (res) => ({
//   type: actionTypes.CHANGE_NEW_RANKING,
//   newRanking: res.playlist
// })

// const changeOriginRankingAction = (res) => ({
//   type: actionTypes.CHANGE_ORIGIN_RANKING,
//   originRanking: res.playlist
// })

// export const getTopBannerAction = () => {
//   return dispatch => {
//     getTopBanners().then(res => {
//       dispatch(changeTopBannerAction(res));
//     })
//   }
// };

// export const getHotRecommendAction = (limit) => {
//   return dispatch => {
//     getHotRecommends(limit).then(res => {
//       dispatch(changeHotRecommendAction(res));
//     })
//   }
// }

// export const getNewAlbumAction = (limit) => {
//   return dispatch => {
//     getNewAlbums(limit).then(res => {
//       // const albums = res.albums;
//       dispatch(changeNewAlbumAction(res));
//     })
//   }
// }

// export const getTopListAction = (idx) => {
//   return dispatch => {
//     getTopList(idx).then(res => {
//       switch (idx) {
//         case 0:
//           dispatch(changeUpRankingAction(res));
//           break;
//         case 2:
//           dispatch(changeNewRankingAction(res));
//           break;
//         case 3:
//           dispatch(changeOriginRankingAction(res));
//           break;
//         default:
//       }
//     });
//   }
// }
